# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:article_list_zip_file_list.py
@Time:2024/9/12 15:09

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""

import os
from gongbao_quanguo.url2list import url_list, extract_reports
# from gongbao_quanguo.bianli_quanguo_gongbao import folder_path

# 得到公报网址列表
def get_article_list():
    base_url = 'https://www.stats.gov.cn/sj/tjgb/ndtjgb/qgndtjgb/'
    num_pages = 4  # 总页数
    all_article_list =[]
    # 生成链接列表
    urls = url_list(base_url, num_pages)
    # print("获取的公报地址如下：\n")
    for url in urls:
        # 获取报告链接
        article_list = extract_reports(base_url, url)
        # print(article_list)
        # print("获取的公报地址如下：\n")
        if article_list:
            for article in article_list:
                pass
                # print("获取的公报地址如下：\n")
                # print(article[0], article[1])
        else:
            print('文件列表为空！')
        all_article_list.append(article_list)

    return all_article_list


# 遍历output_txt 下文件，得到文件列表
def get_file_list(folder_path):
    # folder_path = "gongbao_quanguo/output_txt/"
    file_list = []
    for filename in os.listdir(folder_path):
        if filename.endswith(".txt"):  # 检查文件是否为文本文件
            file_list.append(filename)

    return file_list

# folder_path = "gongbao_quanguo/output_txt/"

# art_list = get_article_list()
# art_list = [element for sublist in art_list for element in sublist]
# # art_list = art_list.sort(reverse=True)
# # art_list = sorted(art_list, key=lambda x: x[0], reverse=True)
# # 删除“七五时期”项
# art_list = [item for item in art_list if item[0] != '七五时期']
# # 按年份正序排列
# art_list = sorted(art_list, key=lambda x: x[0])
# art_list = [link for _, link in art_list]
#
# file_list = get_file_list()
# # 删除含 “七五”项
# file_list = [file for file in file_list if "七五" not in file]
#
# combined_list = list(zip(file_list, art_list))
# dictionary = dict(zip(file_list, art_list))
# print(art_list)
# print(file_list)
# print(combined_list)
# print(dictionary)
